package com.googlecode.mailnet.emf.netmodel.visualization.failureprobability;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Shape;
import org.eclipse.swt.graphics.Color;

import com.googlecode.mailnet.emf.netmodel.simulation.SimulationContext;
import com.googlecode.mailnet.emf.netmodel.visualization.ShapeDecorator;
import com.googlecode.mailnet.info.INodeInfo;

public class FailureProbabilityNodeDecorator extends ShapeDecorator {
	INodeInfo nodeInfo;
	SimulationContext context;
	
	public FailureProbabilityNodeDecorator(INodeInfo nodeInfo, SimulationContext context) {
		this.nodeInfo = nodeInfo;
		this.context = context;
	}
	
	public boolean outlineShape(Shape shape, Graphics g) {
		double failureProbability = context.getStatistics().getNodeStats(nodeInfo.getNode()).normalizedFailureProbability;
		long colorBrightness = Math.round(failureProbability * 127.0);
		Color color = new Color(null, 128 + (int)colorBrightness, 128 - (int)colorBrightness, 128 - (int)colorBrightness);
		shape.setForegroundColor(color);
		shape.setLineStyle(Graphics.LINE_SOLID);
		return false;
	}
	
	public boolean fillShape(Shape shape, Graphics g) {
		double failureProbability = context.getStatistics().getNodeStats(nodeInfo.getNode()).normalizedFailureProbability;
		long colorBrightness = Math.round(failureProbability * 127.0);
		Color color = new Color(null, 128 + (int)colorBrightness, 128 - (int)colorBrightness, 128 - (int)colorBrightness);
		shape.setBackgroundColor(color);
		//shape.setLineStyle(Graphics.LINE_SOLID);
		return false;
	}
}
